/**
 * 
 */
package pms.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import pms.om.Kategorie;

/** 
 * Controller to generate the Home Page basics to be rendered by a view. 
 * It extends the convenience class AbstractController that encapsulates most 
 * of the drudgery involved in handling HTTP requests. 
/**
 * @author roman.zaglauer@googlemail.com
 *
 */
public class SaveMusikstueck extends AlleMusikstuecke{
	protected ModelAndView handleRequestInternal(
			HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		httpServletRequest.setCharacterEncoding("UTF-8");
		
		int id = Integer.parseInt(httpServletRequest.getParameter("id"));
		int kategorieId = Integer.parseInt(httpServletRequest.getParameter("kategorie"));
		Kategorie kategorie = getMusikstueckDao().getKategorieDao().findById(kategorieId);
		
		String titel = httpServletRequest.getParameter("titel");
		String untertitel = httpServletRequest.getParameter("untertitel");
		String komponist = httpServletRequest.getParameter("komponist");
		String verlag = httpServletRequest.getParameter("verlag");
		
		if (id == 0) {
			getMusikstueckDao().create(titel, untertitel, komponist, verlag, kategorie);
		} else {
			getMusikstueckDao().modify(id, titel, untertitel, komponist, verlag, kategorie);
		}

		return super.handleRequestInternal(httpServletRequest, httpServletResponse);	
	}
		
}
